package cn.sskxyz.mybatis.dialect;

import cn.sskxyz.mybatis.mode.Page;

public class OraclePageDialect implements PageDialect {
    @Override
    public String countSql(String sql) {
        return "select count(*) from (" + sql + ")t";
    }

    @Override
    public String pageSql(String sql, Page page) {
        int begin = (page.getPageNo() - 1) * page.getPageSize();
        int end =  begin + page.getPageSize();
        String condition = " where t._db_row_no > %d and t._db_row_no <= %d ";
        condition = String.format(condition, begin, end);
        return "select t.* from (" + sql + ")t " + condition;
    }
}
